package com.chezhujie.www.service;

import com.chezhujie.www.domain.Czjcommodity3;
import com.chezhujie.www.persistence.Czjcommodity3Mapper;
import com.sys.core.page.Pagination;
import com.sys.core.utils.UUIDUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 首页3个商品表
 * Created by 汤伟杰 on 2017/5/23.
 */
@Service
public class Czjcommodity3Service {
    @Autowired
    private Czjcommodity3Mapper czjcommodity3Mapper;
    @Autowired
    private CzjcommodityService czjcommodityService;

    public Pagination list(int pageNo, int pageSize, Map<String, Object> params, ModelMap model) throws Exception {

        Pagination pagination = new Pagination();
        pagination.setPageNo(pageNo);
        pagination.setPageSize(pageSize);
        params.putAll(pagination.toMap());
        int count = czjcommodity3Mapper.getTotalRows(params);
        List<Map<String, Object>> list = czjcommodity3Mapper.getList(params);
        for (int i = 0; i < list.size(); i++) {
            if(list.get(i).get("picPath2")!=null){
                if(StringUtils.isNotBlank(String.valueOf(list.get(i).get("picPath2")))){
                    list.get(i).put("picPath",String.valueOf(list.get(i).get("picPath2")));
                }
            }

        }
        pagination.setTotalCount(count);
        pagination.setList(list);

        return pagination;
    }


    public void insert(Czjcommodity3 czjcommodity3){
        if(StringUtils.isNotBlank(czjcommodity3.getId())){
        czjcommodity3.setId(UUIDUtils.getUUID());
        }
        czjcommodity3Mapper.insert(czjcommodity3);
    }

    public void update(Czjcommodity3 czjcommodity3){
        czjcommodity3Mapper.update(czjcommodity3);
    }
    public void deleteById(String id){
        czjcommodity3Mapper.deleteById(id);
    }
    public void deleteByIds(List<String> list){
        czjcommodity3Mapper.deleteByIds(list);
    }
    public Czjcommodity3 queryById(String id){
        return czjcommodity3Mapper.queryById(id);
    }
    public List<Czjcommodity3> queryByIds(List<String> list){
        List<Czjcommodity3> listCzjcommodity3 = czjcommodity3Mapper.queryByIds(list);
        if(listCzjcommodity3==null){
            listCzjcommodity3 = new ArrayList<Czjcommodity3>();
        }
        return listCzjcommodity3;
    }
    public List<Map<String,Object>> getListCommodityId(Map<String, Object> param) {
        return czjcommodity3Mapper.listCommodityId(param);
    }
    public List<Map<String,Object>> getList(Map<String, Object> param){
        return czjcommodity3Mapper.getList(param);
    }

    public void checkEntity(Czjcommodity3 czjcommodity3) throws Exception {


    }

    public List<Map<String,Object>> getList3(HashMap<String, Object> stringObjectHashMap) {
        return czjcommodity3Mapper.getlist3(stringObjectHashMap);
    }


    public void saves(List<Czjcommodity3> listCommodity3) {
        czjcommodity3Mapper.saves(listCommodity3);
    }

    public List<Map<String,Object>> getListBusinessId(Map<String, Object> param) {
        return czjcommodity3Mapper.getListBusinessId(param);
    }


	public void deleteByCommId(String id) {
		czjcommodity3Mapper.deleteByCommId(id);
	}



    public List<Map<String,Object>> getCommodity3AllAnd(Map<String, Object> param) {
        List<Map<String, Object>> listmap = getList3(new HashMap<String, Object>());
        for (int i = 0; i < listmap.size(); i++) {
            if(listmap.get(i).get("picPath")!=null) {
                if (StringUtils.isNotBlank(String.valueOf(listmap.get(i).get("picPath")))) {
                    listmap.get(i).put("defaultImage", String.valueOf(listmap.get(i).get("picPath")));
                }
            }
        }
        return listmap;
    }
}
